/*
 * PopupNotificationFrame.hpp
 *
 *  Created on: Jul 29, 2012
 *      Author: guillou
 */

#ifndef POPUPNOTIFICATIONFRAME_HPP_
#define POPUPNOTIFICATIONFRAME_HPP_

#include <ui_notificationframe.h>
#include <QTimer>
#include <stdio.h>
struct PopupNotificationFrame : public QDialog, private Ui_NotificationFrame
{
  Q_OBJECT

public:

  PopupNotificationFrame(QDialog *parent)
    : QDialog(parent)
  {
    setupUi(this);
#if QT_VERSION >= 0x040500
    setAttribute(Qt::WA_TranslucentBackground, true);
    setWindowOpacity(0.90);
#endif
    m_timer.setSingleShot(true);
    connect(&m_timer, SIGNAL(timeout()), this, SLOT(slot_timeout()));
  }

  ~PopupNotificationFrame() {}

  void show(const QString & p_message,
            int p_displayTimeMs = -1)
  {
    m_message->setText(p_message);
    if (p_displayTimeMs > 0) {
      m_timer.start(p_displayTimeMs);
    }
    (void) QDialog::exec();
  }

public slots:
  void hide() {
    m_timer.stop();
    QDialog::hide();
  }

signals:
    void signal_timeout();

private slots:
  void slot_timeout() {
    emit(signal_timeout());
    hide();
  }

private:
  QTimer m_timer;
};

#endif /* POPUPNOTIFICATIONFRAME_HPP_ */
